﻿<html>
	<head>
		<title>PHP Test</title>
		<script type="text/javascript" src="scripts/jquery-1.6.2.min.js"></script>
		<script type="text/javascript" src="scripts/sha1.js"></script>
		<script type="text/javascript" src="app/user/ajaxUser.js"></script>
		<script type="text/javascript" src="app/user/UserVerification.js"></script>
		<link rel="stylesheet" type="text/css" href="style.css" />
	</head>
	<body>
		<div align="center" id="register_div">
			<table><tbody>
				<tr>
					<td>Username: </td>
					<td><input type="text" id="username_input" /></td>
					<td><div id="username_info"></div></td>
				</tr>
				<tr>
					<td>Password: </td>
					<td><input type="password" id="password1_input" /></td>
					<td><div id="password1_info"></div></td>
				</tr>
				<tr>
					<td>Confirm password: </td>
					<td><input type="password" id="password2_input" /></td>
					<td><div id="password2_info"></div></td>
				</tr>
			</tbody></table>
			<button type="button" id="register_button">Register</button>
			<button type="button" id="back_button">Back</button>
			<script type="text/javascript">
				$(document).ready(function() {
					$("#register_button").click(function() {
						var validData = true;
						if (!checkUsername($("#username_input").val())) {
							$("#username_info").html("Invalid username");
							validData = false;
						}
						else
							$("#username_info").html("");
						if (!checkPassword($("#password1_input").val())) {
							$("#password1_info").html("Invalid password");
							validData = false;
						}
						else
							$("#password1_info").html("");
						if ($("#password1_input").val() != $("#password2_input").val()) {
							$("#password2_info").html("Not the same password");
							validData = false;
						}
						else
							$("#password2_info").html("");
							
						if (validData) {
							registerUser($("#username_input").val(), SHA1($("#password1_input").val()));
						}
							
					});
					
					$("#back_button").click(function() {
						history.go(-1);
					});
				});
			</script>
		</div>
	</body>
</html>